<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<script type="text/javascript">
    /**
     * 自定义验证规则
     */
    function validateForm(){
        form.bootstrapValidator({
            message: "无效的值",
            feedbackIcons: {
                valid: "glyphicon glyphicon-ok",
                invalid: "glyphicon glyphicon-remove",
                validating: "glyphicon glyphicon-refresh"
            },
            fields: {
                navigationName: {
                    validators: {
                        notEmpty: {message: "前台导航条名称不可为空"},
                        stringLength: {max: 20,message: "前台导航条名称最大长度为20"}
                    }
                },
                navigationUrl: {
                    validators: {
                        notEmpty: {message: "前台导航条url不可为空"},
                        stringLength: {max: 200,message: "前台导航条url最大长度为200"}/*,
                        regexp: {
                            regexp: validateUtil.webUrl,
                            message: '请输入有效的网址'
                        }*/
                    }
                },
                sortCode: {
                    validators: {
                        notEmpty: {message: "前台导航条排序号不可为空"},
                        stringLength: {max: 4,message: "前台导航条排序号最大长度为4"},
                        numeric: {
                            message: '只能输入数字'
                        }
                    }
                },
                seoTitle: {
                    validators: {
                        stringLength: {max: 50,message: "前台导航条SEO标题最大长度为50"}
                    }
                },
                seoKeyWords: {
                    validators: {
                        stringLength: {max: 150,message: "前台导航条SEO关键字最大长度为150"}
                    }
                },
                seoDescrible: {
                    validators: {
                        stringLength: {max: 150,message: "前台导航条SEO简介最大长度为150"}
                    }
                }
            }
        });
    }

    /**
     * 添加首页导航条信息
     */
	<shiro:hasPermission name="back_gotoNavigationPage_add">
    function addInfo(){
        $("#myModalLabel").empty().text("添加首页导航条信息");
        /**清空隐藏域的值**/
        $("#navigationId").val("");
        resetAddForm();
    }
	</shiro:hasPermission>

    /**
     * 编辑首页导航条信息
     */
	<shiro:hasPermission name="back_gotoNavigationPage_delete">
    function editInfo(){
        $("#myModalLabel").empty().text("修改首页导航条信息");
        /**获取选中行的id**/
        var selectedRow= $("#tt").bootstrapTable('getSelections');
        if(selectedRow.length==1){
            var id=selectedRow[0].navigationId;
            $("#btn_edit").attr("data-target","#addOrEditModal");/**选中了记录后才可打开对应的模态框**/
            $.ajax({
                type: "POST",
                dataType: "JSON",
                url: "${basePath}/back/navigation/getNavigationObject.sjson",
                data: {navigationId:id},
                success: function(result){
                    var data = JSON.parse(result.data);
                    /**隐藏域**/
                    $("#navigationId").val(data.navigationId);
                    /**可见表单控件**/
                    $("#navigationName").val(data.navigationName);
                    $("#navigationUrl").val(data.navigationUrl);
                    $("#sortCode").val(data.sortCode);
                    $("#isShowOnBar_"+data.isShowOnBar).attr("checked",true);
                    $("#seoTitle").val(data.seoTitle);
                    $("#seoKeyWords").val(data.seoKeyWords);
                    $("#seoDescrible").val(data.seoDescrible);
                }
            });
        }else{
            $("#btn_edit").attr("data-target", "");/**没有选中记录不可打开模态框**/
            showMsg("请选择一行记录！");
        }
    }
    </shiro:hasPermission>

</script>
<%--<script type="text/javascript">
	//查询导航条是否已存在
	function checkMeasuringUnit(id){
		var value = $("#navigationName").val();
		if(value != ""){
			$.ajax({
				type:"post",
				url:"${basePath}/back/navigation/checkNavigationName.sjson",
				data:{navigationName:value},
				success:function(data){
					var unitValue=$("#navigationName").val();
					if(unitValue.length<=20){
						if(data.success ==true){
							$("#nameMsg").html("<em style='color:green'>可用</em>");
							$("#save").css("display","");
						}else{
							$("#nameMsg").html("<em style='color:red'>已存在</em>");
							$("#navigationName").focus();
							$("#save").css("display","none");
						}
					}else{
						$("#nameMsg").html("");
						$("#navigationName").focus();
					}
				}
			});
		}else{
			$("#nameMsg").html("");
		}
	}
</script>--%>

<!--添加编辑模态框（Modal） -->
<div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static" >
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="myModalLabel"></h5>
			</div>
			<div class="modal-body">
				<form id="form1"  method="post" action="${basePath}/back/navigation/saveOrUpdateNavigation.sjson">
					<input id="navigationId" type="hidden" name="navigationId" noclear="true"/>
					<table align="center" class="addOrEditTable table-bordered table" style="width:100%;">
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>前台导航条名称:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="navigationName" name="navigationName" placeholder="请输入前台导航条名称"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>前台导航条url:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="navigationUrl" name="navigationUrl" placeholder="请输入前台导航条url"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>前台导航条排序号:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="sortCode" name="sortCode" placeholder="请输入前台导航条排序号"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>是否显示:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<label class="checkbox-inline">
									<input type="radio" name="isShowOnBar" id="isShowOnBar_0" class="radioInput" value="0" checked="checked">&nbsp;未显示
								</label>
								<label class="checkbox-inline">
									<input type="radio" name="isShowOnBar" id="isShowOnBar_1" class="radioInput" value="1">&nbsp;已显示
								</label>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">前台导航条SEO标题:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="seoTitle" name="seoTitle" placeholder="请输入前台导航条SEO标题"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">前台导航条SEO关键字:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="seoKeyWords" name="seoKeyWords" placeholder="请输入前台导航条SEO关键字"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">前台导航条SEO简介:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="seoDescrible" name="seoDescrible" placeholder="请输入前台导航条SEO简介"/>
								</div>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="validateBtn" class="btn btn-primary"  onclick="submitForm()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
